import { Controller, Get, Post, Put, Body, Query, Param, Delete } from '@nestjs/common';
import { ApiTags, ApiOperation } from '@nestjs/swagger';
import { RequirePermission } from 'src/common/decorators/require-premission.decorator';
import { TemplateService } from './template.service';
import { CreateTemplateDto, BaseTemplateDto, UpdateTemplateDto, QueryTemplateDto, ListTemplateDto } from './dto/template.dto';
import { ApiDataResponse } from 'src/common/decorators/apiDataResponse.decorator';

@ApiTags('模板信息表')
@Controller('system/template')
export class TemplateController {
  constructor(private readonly templateService: TemplateService) {}

  @ApiOperation({ summary: '模板信息表-创建' })
  @ApiDataResponse(BaseTemplateDto)
  @RequirePermission('system:template:add')
  @Post()
  create(@Body() body: CreateTemplateDto) {
    return this.templateService.create(body);
  }

  @ApiOperation({ summary: '模板信息表-列表' })
  @ApiDataResponse(ListTemplateDto, true, true)
  // @RequirePermission('system:template:list')
  @Get('list')
  findAll(@Query() query: QueryTemplateDto) {
    return this.templateService.findAll(query);
  }

  @ApiOperation({ summary: '模板信息表-详情' })
  @ApiDataResponse(BaseTemplateDto)
  @RequirePermission('system:template:query')
  @Get(':id')
  findOne(@Param('id') id: number) {
    return this.templateService.findOne(id);
  }

  @ApiOperation({ summary: '模板信息表-修改' })
  @ApiDataResponse()
  @RequirePermission('system:template:edit')
  @Put()
  update(@Body() body: UpdateTemplateDto) {
    return this.templateService.update(body);
  }

  @ApiOperation({ summary: '模板信息表-删除' })
  @ApiDataResponse()
  @RequirePermission('system:template:remove')
  @Delete(':id')
  remove(@Param('id') id: string) {
    const ids = id.split(',').map((id) => +id);
    return this.templateService.remove(ids);
  }
}
